<?php
// Systems can temporarily force a reload by setting the variable
// $ForceConfigReload to true
if (isset ( $ForceConfigReload ) and $ForceConfigReload == TRUE or ! isset ( $_SESSION ['CompanyDefaultsLoaded'] )) {
	$sql = 'SELECT confname, confvalue FROM config';
	// dont care about the order by
	$ConfigResult = DB_query ( $sql, $db );
	while ( $myrow = DB_fetch_array ( $ConfigResult, SQLSRV_FETCH_ASSOC ) ) {
		if (is_numeric ( $myrow ['confvalue'] ) and $myrow ['confname'] != 'DefaultPriceList') {
			// the variable name is given by $myrow[0]
			$_SESSION [$myrow ['confname']] = ( double ) $myrow ['confvalue'];
		} else {
			$_SESSION [$myrow ['confname']] = $myrow ['confvalue'];
		}
	} // end loop through all config variables
	$_SESSION ['CompanyDefaultsLoaded'] = true;
	DB_free_result ( $ConfigResult );
	// no longer needed
	/* Maybe we should check config directories exist and try to create if not */

    /* Also reads all the company data set up in the company record and returns an array */
    $ReadCoyResult = _single ( 'api/company' )->GetCompanyById ( 1, $_SESSION ['UserID'], $_SESSION ['Password'] );
	if (count ( $ReadCoyResult ) == 0) {
		echo '<BR><B>';
		prnMsg ( _ ( 'The company record has not yet been set up' ) . '</B><BR>' . _ ( 'From the system setup tab select company maintenance to enter the company information and system preferences' ), 'error', _ ( 'CRITICAL PROBLEM' ) );
		exit ();
	} else {
		$_SESSION ['CompanyRecord'] = $ReadCoyResult;
	}
} // end if force reload or not set already

?>
